#ifndef XDIVA_NODEMANAGER_H
#define XDIVA_NODEMANAGER_H

#include "AbstractManager.h"
#include <vector>
#include <map>

class AbstractMappingWindow;
class NodeItem;
class LineItem;
class EntryItem;
class TerminalNodeShape;
class xMappingTree;
class VariableEntry;
class NodePort;
class NodeInPort;
class NodeOutPort;
class WOP_Entry;
class xMappingNode;
class AbstractShapeItem;
class VariablePanel;
class QPointF;
class EntryFrameItem;
class DiagramScene;

class NodeManager
	: public AbstractManager
{
	Q_OBJECT

public:
	
	NodeManager(AbstractMappingWindow* );
	~NodeManager(void);

	virtual AbstractPanel * createInputPanel();
	virtual AbstractPanel * createOutputPanel();

	EntryItem* createEntryItem(std::string, std::string, xMappingNode*,WOP_Entry*,EntryFrameItem* =0);
	void createEntry(WOP_Entry* , bool );
	void deleteEntry();
	void createArrEntry( WOP_Entry* );
	void createPtvEntry( WOP_Entry* );
	void createRefEntry( WOP_Entry* );
	void createObjEntry( WOP_Entry* );
	VariableEntry* getEntry();
	void initVariableEntry( WOP_Entry* );
	void unfoldEntry( WOP_Entry* );
	NodeItem* getRootNode();
	void saveMapping(QString ,WOP_Entry* );

	void setSaveFileName(QString);
	QString getSaveFileName()const;
	void addMDSString(WOP_Entry*);		//add mds string in diva
	void deleteEmptyPort();
	
	NodeItem* getRoot();
	bool checkRootNumberValidate();
	void reset();
	VariablePanel* getVariablePanel();
	std::vector<EntryItem*> createUnfoldEntries(WOP_Entry *entry);
	void createEntryFrameItem(WOP_Entry* entry, std::vector<xMappingNode*> &entryList, DiagramScene* scene, AbstractPanel* panel);

	NodeItem * createNode( WOP_Entry * en );

protected:
	QString _saveFileName;	// mapping tree 存成 mds檔案的檔名
	VariableEntry* _mpnEntry;
	NodeItem* _root;			// 最後連接到TerminalNode的mapping node
	VariablePanel* iPanel_;
	EntryItem* findEntryItemByName( std::string );
	
};

#endif
